<!DOCTYPE HTML>
 <?php session_start();?>
<html>
	<head>			
		<title>日志界面</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<link rel="stylesheet" type="text/css" href="rizhistyle.css"/>
	</head>
	
	<body>
		<?php
			//连接数据库
		   $conn;
		   include'../public/conn.php';
		   include'../public/header.php';
		?>

		<!-- 文章展示 -->

		<section>
		<!-- 读取数据 -->	   
			<?php
			echo $_GET['id'];
			   if(!empty($_GET['id'])){
					$sql="select * from log where log_id = '".$_GET['id']."'";
					$query = mysql_query($sql);
					$row = mysql_fetch_array($query);
				}
				
			   $sID = $row['sid'];
			   $id_sql="select sna from student where sid = '$sID'";
			   $id_query = mysql_query($id_sql);
			   $id_row = mysql_fetch_array($id_query);
			   $id_row['sna']
			 ?>
			 
			<!-- 标题 -->
			<p><?php echo $row['log_title'];?></p>
			<hr/>
			
			&#12288;&#12288;
				 <?php echo $row['log_content'];?>
					<?php if($row['photo'] == "") {
							 echo "";
						  }
						  else{
					?>
					<br/>
					<?php echo "<img src= \"{$row['photo']}\" width = 300px; height=200px;/>";}?>
		</section>			
		
	<!-- 作者信息 -->	
		<div id="stu">
			<img id="stuimg" src="sinfor.jpg"/>
			LOG information:
		    <p>log_unit:Module <?php echo $row['unit_id'];?></p>
		    <p>writer_ID:<?php echo $row['sid'];?></p>
			<p>writer_name:<?php echo $id_row['sna'];?></p>
			<p>date:<?php echo $row['log_date'];?></p>
		</div>
        
        
	<!-- 最新日志 -->	
		<aside>
			<h2>The newest record</h2>
			<ul>
				    
      			<?php
      			    
      			    $userType = $_SESSION['userType'];
      			    //echo $userType;
					if($userType == '0'){
						if(!empty($_POST['search'])){
							$search = $_POST['search'];
						}

					else{
					    $search=NULL;
					}
		               
				    //读取最新日志
				    $search_res = mysql_query("select * from log ORDER BY log_date DESC,log_time DESC LIMIT 8" , $conn);
				    $rows = mysql_num_rows($search_res);
				    $row = mysql_fetch_array($search_res);
				
                    //循环输出用户日志
					for($i=0; $i<8; $i++){

						$title = $row['log_title'];
				        $log_date = $row['log_date'];
				        $log_time = $row['log_time'];
				?> 
				<li><a href="../log/log_read.php?id=<?php echo $row['log_id'];?>"><?php echo ($i+1).". ".$title."--------------".$log_date."--".$log_time;; ?></a></li>
				<?php 
					$row = mysql_fetch_array($search_res);
				       }
		/* ? */		}
					else{
						if(!empty($_POST['search'])){
						$search = $_POST['search'];
					}

					else{
					    $search=NULL;
					}

				    //读取最新日志
				    $search_res = mysql_query("select * from log ORDER BY log_date DESC,log_time DESC LIMIT 8" , $conn);
				    $rows = mysql_num_rows($search_res);
				    $row = mysql_fetch_array($search_res);
				
                    //循环输出用户日志
					for($i=0; $i<8; $i++){
						if($row['log_visible'] =='1'){
						$title = $row['log_title'];
				        $log_date = $row['log_date'];
				        $log_time = $row['log_time'];
				?>
				        <li><a href="../log/log_read.php?id=<?php echo $row['log_id'];?>"><?php echo ($i+1).". ".$title."---".$log_date."-".$log_time; ?></a></li>
				        <?php 
					$row = mysql_fetch_array($search_res);
					    }
					    else if($row['log_visible'] =='0'  ){?>
					    	 <li><a href="../log/log_secret.php?id=<?php echo $row['log_id'];?>"><?php echo ($i+1).".私密 "; ?></a></li>
					  <?php  $row = mysql_fetch_array($search_res);
					        } 
				       }
				   }
			    ?>
			</ul>
		</aside>
		
		<footer>
		<!-- 查看评论 -->
			<h3>Comment</h3>
			
			<div>
				 <?php
				 //读取数据
					 if(!empty($_GET['id'])){
						$sql="select * from reply where log_id = '".$_GET['id']."'";

						$query = mysql_query($sql);
						$row = mysql_fetch_array($query);
					}	 
					 //循环输出用户日志
				?>
				<?php  
				for($i=0; $i<5; $i++){
				?>
				<div><?php echo ($i+1).". ".$row["reply_content"].". ".$row["sid"]."--------".$row["reply_date"]."-".$row["reply_time"] ;?></div>
				
				<?php 
					$row = mysql_fetch_array($query);
				}?>
			</div>
		</footer>
		
<!--发表评论-->		
		<div id="comment">
		  <h3>Your Comment</h3>
			<form action="reply.php" method="post" >
				<input style="display:none;" name="log_id" value="<?php echo $_GET['id'];?>" />
				<textarea id="reply_content" name="reply_content" name="txt"></textarea>
				<input type="submit" value="Submit" class="ins"/>
				<input type="reset" value="Reset" class="ins"/>
			</form>		
		</div>		
	</body>
</html>